function formatTable(){
	
	var tables = document.getElementsByTagName("table");
	
	for(var i = 0; i < tables.length; i++){
		//if(tables[i].className =="format"){
			//tables[i].border=1;
			var rows = tables[i].getElementsByTagName("tr");
			
			topCells = rows[0].getElementsByTagName('td');
			if(topCells.length ==0){
				topCells = rows[0].getElementsByTagName('th');
			}
			
			var cellfontsize = '12px';
			
			if(topCells.length > 7){
				cellfontsize = '9.5px';
			}else if(topCells.length > 5){
				cellfontsize = '10px';
			}else if(topCells.length > 3){
				cellfontsize = '11px';
			}

			
			for(var j = 0; j < rows.length; j++){
				if (j % 2 == 0){
					rows[j].style.backgroundColor = "#eee";
				}else{
					rows[j].style.backgroundColor = "#fff";
				}
				
				var headers = rows[j].getElementsByTagName("th");
				for(var p = 0; p < headers.length; p++){
					
					headers[p].style.fontSize = cellfontsize;
					
					if (headers[p].innerHTML.indexOf("input") > 0){
						headers[p].style.textAlign = "left";
					}
				}
				
				var cells = rows[j].getElementsByTagName("td");
				
				var totalLine = false;
				if(cells.length > 0){
					if(cells[0].innerHTML.toLowerCase().indexOf("total") > -1){
						totalLine = true;
					}
				}
				
				for(var k = 0; k < cells.length; k++){
				
					cells[k].style.fontSize = cellfontsize;
					
					var moveRight = false;
					
					var cellContent = trim(cells[k].innerHTML);
					if (isNumber(cellContent.substring(0,5))){
						moveRight = true;
					}
					
					if (trim(cells[k].innerHTML).indexOf("$") > 0){
						moveRight = true;
					}
					
					if (trim(cells[k].innerHTML).indexOf("<input") > 0){
						moveRight = false;
					}
					
					if (moveRight){
						cells[k].style.textAlign = "right";
					}else{
						cells[k].style.textAlign = "left";
					}
					
					if(totalLine){
						cells[k].style.fontWeight = "bold";
					}
				
				}
				
			}
			
		//}
	}
}

function isNumber(cellData)
{
	var reg = new RegExp("[0-9.]+");
	return (reg.test(cellData));
}

function trim( str ){
 var start = -1,
  end = str.length;
 while( str.charCodeAt(--end) < 33 );
 while( str.charCodeAt(++start) < 33 );
 return str.slice( start, end + 1 );
};
